package org.alwayssuper.protocol.commons.transform.realtimev2016.enums;

/**
 * 报警等级枚举 (报警数据 0x07)
 * 基于 GB/T 32960.3-2016 标准
 * @author alwaysSuper
 */
public enum AlarmLevel {
    NO_FAULT(0, "无故障"),
    LEVEL_1(1, "1级故障"),
    LEVEL_2(2, "2级故障"),
    LEVEL_3(3, "3级故障"),
    INVALID(0xFF, "无效");

    private final int level;
    private final String description;

    AlarmLevel(int level, String description) {
        this.level = level;
        this.description = description;
    }

    public int getLevel() {
        return level;
    }

    public String getDescription() {
        return description;
    }

    public static AlarmLevel fromLevel(int level) {
        for (AlarmLevel alarmLevel : values()) {
            if (alarmLevel.level == level) {
                return alarmLevel;
            }
        }
        return INVALID;
    }

    @Override
    public String toString() {
        return String.format("AlarmLevel{level=%d, description='%s'}", level, description);
    }
}